module.exports = class Base extends colpu.Service {
  constructor(ctx) {
    super(ctx);
    this.utils = ctx.utils;
  }

  installParams(params, mode = 0) {
    const as = params.as ? `${params.as}.` : '';
    delete params.as;
    for (let key in params) {
      if (params[key] === undefined) {
        delete params[key];
      }
    }
    const keys = Object.keys(params).map(key=>`\`${key}\``);
    const replacements = Object.values(params);
    const values = ('?'.repeat(keys.length)).split('');
    let returnData;
    switch (mode) {
      case 1:
        returnData = {
          values: `${as}${keys.join(`=? AND ${as}`)}${keys.length? '=?' :''}`,
          replacements
        };
        break;
      case 2:
        returnData = {
          values: `${keys.join('=?, ')}${keys.length? '=? ' :''}`,
          replacements
        };
        break;

      default:
        returnData = {
          keys: keys.join(','),
          replacements,
          values: values.join(',')
        };
        break;
    }
    return returnData;
  }
}
